package com.graduationproject.examonline.schoolClass.service;

import com.graduationproject.examonline.schoolClass.entity.SchoolClass;
import com.graduationproject.examonline.schoolClass.mapper.ClassMapper;
import com.graduationproject.examonline.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ClassService {

    @Autowired
    private ClassMapper classMapper;

    public Result findAllClass() {
        try {
            List<SchoolClass> resultList = classMapper.findAllClass();
            return new Result(0, 200, "查询成功", resultList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1, 501, "服务器出错");
        }
    }

    public Result findClassById(String classId) {
        try {
            List<SchoolClass> resultList = classMapper.findClassById(classId);
            return new Result(0, 200, "查询成功", resultList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1, 500, "查询失败，未知错误");
        }
    }

    public Result updateById(Map<String, Object> p) {
        try {
            classMapper.updateClassById(p);
            return new Result(0, 200, "ok");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1, 500, "error");
        }
    }

    public Result insertClass(String class_id) {
        try {
            classMapper.createClass(class_id);
            return new Result(0, 200, "ok");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1, 500, "error");
        }
    }
}
